export default {
  _insertimg: function (el, str) {
    // 获取页面选中元素
    var selection = window.getSelection ? window.getSelection() : document.selection
    var range = selection.createRange ? selection.createRange() : selection.getRangeAt(0)
    if (!window.getSelection) { // 没有选取
      el.focus()
      range.pasteHTML(str)
      range.collapse(false)
      range.select()
    } else {
      el.focus()
      range.collapse(false)
      var hasR = range.createContextualFragment(str)
      var hasRLastChild = hasR.lastChild
      while (hasRLastChild && hasRLastChild.nodeName.toLowerCase() === 'br' && hasRLastChild.previousSibling && hasRLastChild.previousSibling.nodeName.toLowerCase() === 'br') {
        var e = hasRLastChild
        hasRLastChild = hasRLastChild.previousSibling
        hasR.removeChild(e)
      }
      range.insertNode(hasR)
      if (hasRLastChild) {
        range.setEndAfter(hasRLastChild)
        range.setStartAfter(hasRLastChild)
      }
      selection.removeAllRanges()
      selection.addRange(range)
    }
  }
}
